#!/bin/sh
# PCP QA Test No. 843
# Exercise memory_python PMDA
#
# Copyright (c) 2014 Red Hat.
#

seq=`basename $0`
echo "QA output created by $seq"

. ./common.python

$python -c "from pcp import pmda" >/dev/null 2>&1
[ $? -eq 0 ] || _notrun "python pcp pmda module not installed"

_cleanup()
{
    if pmprobe -I pmcd.agent.status | grep '"memory_python"' >/dev/null
    then
	cd $here/pmdas/memory_python
	$sudo ./Remove >>$here/$seq.full 2>&1
	$sudo rm -f pmns
	cd $here
    fi
}

status=1	# failure is the default!
$sudo rm -rf $tmp.* $seq.full
trap "cd $here; rm -rf $tmp.*; _cleanup; exit \$status" 0 1 2 3 15

cd pmdas/memory_python
$PCP_MAKE_PROG clean >>$here/$seq.full 2>&1

# real QA test starts here
echo | tee -a $here/$seq.full
date >>$here/$seq.full
$sudo ./Install </dev/null
date >>$here/$seq.full
# Read metrics several times to make sure memory doesn't get corrupted
# when clearing metrics.
pminfo -f memory_python | tee -a $here/$seq.full
pminfo -f memory_python | tee -a $here/$seq.full
pminfo -f memory_python | tee -a $here/$seq.full
pminfo -f memory_python | tee -a $here/$seq.full
pminfo -f memory_python | tee -a $here/$seq.full
$sudo cat $PCP_LOG_DIR/pmcd/memory_python.log >>$here/$seq.full
$sudo tail -40 $PCP_LOG_DIR/pmcd/pmcd.log >>$here/$seq.full

# success, all done
status=0

exit
